<template>
  <div id="nav">
    <router-link to="/">Home</router-link> |
    <router-link to="/about">About</router-link>|
    <router-link to="/grould">grould</router-link>
     <router-view/>
  </div>
 
</template>
<script>
// import { useStore } from 'vuex'
import {  useStore } from 'vuex'
export default {
  data(){
    return{
      
    }
  },
  
  created () {
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("store") ) {
        this.$store.replaceState(Object.assign({}, this.$store.state,JSON.parse(sessionStorage.getItem("store"))))
    } 
// console.log("1213")
    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload",()=>{
        sessionStorage.setItem("store",JSON.stringify(this.$store.state))
    })
  },
  setup () {
    // 1. 使用vuex仓库
    const store = useStore()
    // 1. 使用根模块state的数据
    // console.log(store.state.username)
    
    // 2.使用根模块getters的数据
    // console.log(store.getters.newName)
    // const agg=store.state.arr.data.data.forecast[0].high
    const mutationsFn = () => {
      // 3. 提交根模块mutations函数
      // store.commit('updateName')
      // 4.调用根模块actions函数
      store.dispatch('updateName')
    }
    // store.dispatch("")
    // console.log(this.data.info)
    return { mutationsFn }
  },
  mounted(){
     
  },
  methods(){
      
  }
}
</script>
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  /* padding: 30px; */
}
body{
  margin: 0;
  padding: 0;
}
#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
